package com.example.administrator.qimo3no74.orders;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;
import com.robertlevonyan.views.chip.Chip;
import com.robertlevonyan.views.chip.OnChipClickListener;

import java.util.List;

public class OrdersItemAdapter extends RecyclerView.Adapter<OrdersItemAdapter.ViewHolder> {

    private List<OrdersItem> ordersItems;



    static  class ViewHolder extends RecyclerView.ViewHolder{
        ImageView itemImg;
        TextView itemName;
        TextView itemCount;
        TextView ordersTextViewHeji;
        TextView itemUnitPrice;
        TextView itemPrice;
        TextView storeName;
        TextView itemOther;
        TextView orderTextViewMore;
        Chip orderChipLogistics;
        Chip orderChipSell;
        Chip orderChipEvaluate;


        public ViewHolder(View itemView, final Context context){
            super(itemView);
            this.itemImg = itemView.findViewById(R.id.orderImageView);
            this.itemName = itemView.findViewById(R.id.orderTextViewItemName);
            this.itemCount = itemView.findViewById(R.id.orderTextViewItemCount);
            this.itemUnitPrice = itemView.findViewById(R.id.orderTextViewUnitPrice);
            this.itemPrice = itemView.findViewById(R.id.orderTextViewPrice);
            this.storeName = itemView.findViewById(R.id.orderTextViewStoreName);
            this.itemOther = itemView.findViewById(R.id.orderTextViewItemOther);
            this.orderTextViewMore = itemView.findViewById(R.id.orderTextViewMore);
            this.orderChipLogistics = itemView.findViewById(R.id.orderChipLogistics);
            this.orderChipSell = itemView.findViewById(R.id.orderChipSell);
            this.orderChipEvaluate = itemView.findViewById(R.id.orderChipEvaluate);
            this.ordersTextViewHeji = itemView.findViewById(R.id.ordersTextViewHeji);

            orderTextViewMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,"还有更多功能哦",Toast.LENGTH_SHORT).show();
                }
            });

            orderChipLogistics.setOnChipClickListener(new OnChipClickListener() {
                @Override
                public void onChipClick(View v) {
                    Toast.makeText(context,"查看物流信息",Toast.LENGTH_SHORT).show();
                }
            });
            orderChipSell.setOnChipClickListener(new OnChipClickListener() {
                @Override
                public void onChipClick(View v) {
                    Toast.makeText(context,"卖给谁呢？",Toast.LENGTH_SHORT).show();
                }
            });
            orderChipEvaluate.setOnChipClickListener(new OnChipClickListener() {
                @Override
                public void onChipClick(View v) {
                    Toast.makeText(context,"给好评哦",Toast.LENGTH_SHORT).show();
                }
            });

            itemImg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+itemName.getText(),Toast.LENGTH_SHORT).show();
                }
            });
            itemName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+itemName.getText(),Toast.LENGTH_SHORT).show();
                }
            });
            storeName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,storeName.getText()+" 还有更多精美商品",Toast.LENGTH_SHORT).show();
                }
            });

        }
    }

    public OrdersItemAdapter(List<OrdersItem> ordersItems){
        this.ordersItems = ordersItems;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.orders_item,viewGroup,false);
        ViewHolder holder = new ViewHolder(view,viewGroup.getContext());
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        OrdersItem item = ordersItems.get(i);
        viewHolder.itemImg.setImageResource(item.getItemImgId());
        viewHolder.itemName.setText(item.getItemName());
        viewHolder.ordersTextViewHeji.setText("共"+item.getItemCount()+"件商品  合计:￥");
        viewHolder.itemCount.setText(item.getItemCount().toString());
        viewHolder.itemUnitPrice.setText(item.getItemUnitPrice().toString());
        viewHolder.itemPrice.setText(item.getItemPrice().toString());
        viewHolder.storeName.setText(item.getStoreName());
        viewHolder.itemOther.setText(item.getItemOther());
    }

    @Override
    public int getItemCount() {
        return ordersItems.size();
    }

}
